// 短信验证码发送
function sendSms(data) {
    $.ajax({
        type: "Get",
        url: "http://127.0.0.1:7777/hy-frontuser-consumer/ums_member/send.action",
        data: data,
        dataType: "json",
        async: false,
        success: function (res) {
            var class1 = ".code-box";
            if (res.code == 100 ) {
                ShowTips("<span style='color:mediumvioletred'>验证码已发送请查收</span>", ".code-box");
                counter = 0;
                $("#getcode").hide();
                $("#regetcode").html("90");
                $("#prompt_info").show();
                $("#phoneCode").focus();
                interval = window.setInterval(intervalFunc, 1000);
            }
            else if(res.code==102){
                ShowTips("<span style='color:mediumvioletred'>发送失败</span>",".code-box");
                /* if (res.DataStatus == 1026) {      // 需要图片验证码
                     $("#phoneVerifyBox").show();
                     $("#phonePicCode").focus();
                     class1 = ".verify-box1";
                 }
                 else if (res.DataStatus == 1002) {     // 手机号格式不正确
                     $("#phone").focus();
                     class1 = ".phone-box";
                 }
                 else if (res.DataStatus == 1012) {     // 图片验证码不正确
                     $("#phoneVerifyBox").show();
                     RefreshImage2('imgCaptcha1','phone');
                     $("#phonePicCode").focus();
                     class1 = ".verify-box1";
                 }
                 else if (res.DataStatus == 1003) {     // 短信验证码发送过于频繁
                     class1 = ".code-box";
                 }
                 if (res.DataStatus != 0) {
                     ShowTips(res.ErrMsg || data.Message, class1);
                 }*/
            }else{
                class1 = ".code-box";
                ShowTips("<span style='color:mediumvioletred'>验证码未失效</span>",".code-box");
            }
        }
    });
}

//手机注册
function phoneRegister() {
    //解除按钮 绑定
    $(".reg").unbind('click');
    try {
        var successInterval = null;
        HideTips();
        // 必须：手机、短信验证码、密码
        if (!Check_Phone("phone", ".tel-box")) return false;   // 手机
        //手机号验证是否注册
        /*verifyPhone($("#UserName").val(),function (res) {
            if (res.code == 100){
                ShowTips('手机号已注册!','.tel-box');
                //刷新图形验证码
                //RefreshImage('imgCaptcha1');
                return false;
            }
        });*/
        if (!Check_SmsCode("phoneCode", ".code-box")) return false;  // 短信验证码
        if (!Check_Password("phonePassWord", ".pwd-box1")) return false;   // 密码
        var phone = $("#phone").val().trim();
        var code = $("#phoneCode").val().trim();
        var pwd = $("#phonePassWord").val().trim();
        //var imgCode = Check_Code("phonePicCode", ".verify-box1");     // 图形验证码，非必填
        //获取登录地址
        $.ajax({
            type: "get",
            url: "https://restapi.amap.com/v3/ip?parameters&key=dde806404afaf4ca0ce23f829d6946a5&output=JSON",
            dataType: "json",
            success: function (res) {
                //省份
                var province = res.province;
                //城市
                var city = res.city;
                if(res.status == 1){  //登录地址获取成功
                    //password: pwd, //密码没有加
                    $.ajax({
                        type: "Post",
                        url: "http://127.0.0.1:7777/hy-frontuser-consumer/ums_member/userphonezhuce.action",
                        data: {
                            phone: phone,
                            message:code,
                            province:province,
                            city:city
                        },
                        dataType: "json",
                        async: false,
                        success: function (res) {
                            //var data = res.Datas;
                            if (res.code==100) {   // 注册成功
                                // alert("注册成功");
                                successPop();
                                $("#pop-success-username").html(phone);
                                // 3秒自动跳转首页
                                var counter = 3;
                                var popCountdown = $("#pop-success-countdown");
                                popCountdown.html(counter);
                                //setInterval设置时间
                                successInterval = window.setInterval(function () {
                                    if (counter > 0) {
                                        counter--;
                                        popCountdown.html(counter);
                                    }
                                    else {
                                        //取消由setInterval设置的时间
                                        window.clearInterval(successInterval);
                                        location.href = res.redirectUrl;
                                    }
                                }, 1000);
                            }else if(res.code==104){
                                ShowTips(res.message, ".code-box");
                            }else if(res.code==106){
                                existPop();
                            }
                        }
                    });
                }
            }
        });
    }finally {
        //发送 ajax 延迟绑定
        window.setTimeout(function () {
            //增加绑定
            $(".reg").on("click",phoneRegister);
        },1000);
    }

}